<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%@include file="/websrc/page/common/jsloader.jsp"%>
<%@ page import="global.security.SessionUtils"%>
<%@ page import="global.Constants"%>
<html>
<head>
	<%String baseUrl = request.getContextPath();%>
	<title>Anynote</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript">
		$(document).ready(function(){
			Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
			Ext.QuickTips.init();

			// 如果处于锁定状态，直接退出页面
		    var hasLocked = Ext.state.Manager.get('Anynote_hasLocked');
		    if(hasLocked){
		    	// 发送请求
				Anynote.ajaxRequest({
					baseUrl: '<%=baseUrl %>',
					action: '/loginAction.do?method=logout',
					callback: function(jsonResult){
						Ext.state.Manager.set('Anynote_autoLogin', false);
						location.href="<%=baseUrl %>";
					}
				});
			}else{
				//实际改变风格样式的处理  
	            Ext.util.CSS.swapStyleSheet('theme', '/Anynote/websrc/js/ext-3.3.0/resources/css/<%=SessionUtils.getUserMeta().get("theme")%>');
	            Ext.state.Manager.set('Anynote_theme', '<%=SessionUtils.getUserMeta().get("theme")%>');
				
				// 头部
				Anynote.headerPanel = new Ext.Panel({
					region: 'north',
	                height: 40,
	                border: false,
	                margins: '0 0 0 5',
	                bodyStyle: 'background-color:transparent;',
	                autoLoad:{url:'<%=baseUrl %>/websrc/page/common/header.jsp',scripts:true,nocache:true}
	            });

				// 菜单面板
				Anynote.menuPanel = new Ext.Panel({
					region: 'west',
	                title: '主菜单',
	                split: true,
	                width: 240,
	                minSize: 175,
	                maxSize: 400,
	                collapsible: true,
	                margins: '0',
	                layout:'accordion',
	                layoutConfig: {
	                    animate: true
	                },
					listeners: {collapse: function(){Anynote.resizeActiveTab();}}
				});
				// 添加主页菜单
	   			var homeAccordion = Menu.getHomeAccordion({
	   	   			baseUrl: '<%=baseUrl%>',
	   	   			tabUrl: '<%=baseUrl + SessionUtils.getUserMeta().get("homePage") %>'
	   	   	   	});
	   			Anynote.menuPanel.add(homeAccordion);

	   			// 任务菜单
				if("<%=SessionUtils.getUserMeta().get("showTodo")%>"=="<%=Constants.CHECK_TRUE%>"){
					// 参数
					var param = {};
					param.baseUrl = '<%=baseUrl%>';
					// 任务菜单
	    			var todoAccordion = Menu.getTodoAccordion(param);
	    			Anynote.menuPanel.add(todoAccordion);
				}
				// 笔记菜单
				if("<%=SessionUtils.getUserMeta().get("showNote")%>"=="<%=Constants.CHECK_TRUE%>"){
					// 参数
					var param = {};
					param.baseUrl = '<%=baseUrl%>';
					// 任务菜单
					var noteAccordion = Menu.getNoteAccordion(param);
					Anynote.menuPanel.add(noteAccordion);
				}
				// 相册菜单
				if("<%=SessionUtils.getUserMeta().get("showPicture")%>"=="<%=Constants.CHECK_TRUE%>"){
					// 参数
					var param = {};
					param.baseUrl = '<%=baseUrl%>';
					// 相册菜单
					var pictureAccordion = Menu.getPictureAccordion(param);
					Anynote.menuPanel.add(pictureAccordion);
				}
				// 订阅菜单
				if("<%=SessionUtils.getUserMeta().get("showFeed")%>"=="<%=Constants.CHECK_TRUE%>"){
					// 参数
					var param = {};
					param.baseUrl = '<%=baseUrl%>';
					// 订阅菜单
					var feedAccordion = Menu.getFeedAccordion(param);
					Anynote.menuPanel.add(feedAccordion);
				}
				// 文档菜单
				if("<%=SessionUtils.getUserMeta().get("showDocument")%>"=="<%=Constants.CHECK_TRUE%>"){
					// 参数
					var param = {};
					param.baseUrl = '<%=baseUrl%>';
					// 订阅菜单
					var documentAccordion = Menu.getDocumentAccordion(param);
					Anynote.menuPanel.add(documentAccordion);
				}
				// 账目菜单
				if("<%=SessionUtils.getUserMeta().get("showAccount")%>"=="<%=Constants.CHECK_TRUE%>"){
					// 参数
					var param = {};
					param.baseUrl = '<%=baseUrl%>';
					// 账目菜单
					var accountAccordion = Menu.getAccountAccordion(param);
					Anynote.menuPanel.add(accountAccordion);
				}
				// 系统菜单
				if("<%=SessionUtils.getUserMeta().get("showSystem")%>"=="<%=Constants.CHECK_TRUE%>"){
					// 参数
					var param = {};
					param.baseUrl = '<%=baseUrl%>';
					param.role = '<%=SessionUtils.getUserRole()%>';
					// 系统菜单
					var systemAccordion = Menu.getSystemAccordion(param);
					Anynote.menuPanel.add(systemAccordion);
				}

				// tab主面板
				Anynote.tabPanel = new Ext.TabPanel({
					id: 'mainTabPanel',
					region: 'center',
	                deferredRender: false,
	                activeTab: 0,
	                enableTabScroll: true,
	                plugins: new Ext.ux.TabCloseMenu({
	                	closeTabText: '关闭标签页',
	                	closeOtherTabsText: '关闭其他标签页',
	                	closeAllTabsText: '关闭所有标签页'
		            }),
	                items: [{
	                    id: Anynote.getTabIdByUrl('<%=SessionUtils.getUserMeta().get("homePage").toString() %>'),
	                    title: '我的主页',
	                    iconCls: 'house',
	                    autoLoad:{url:'<%=baseUrl + SessionUtils.getUserMeta().get("homePage") %>',scripts:true,nocache:true}
	                }],
					listeners: {
						tabchange: function(){
										Anynote.resizeActiveTab();
										document.title = Anynote.tabPanel.getActiveTab().title + ' - Anynote';
									}
						}
	            });

				// 初期化页面Layout
				var viewport = new Ext.Viewport({
		            layout: 'border',
		            items: [Anynote.headerPanel, Anynote.menuPanel, Anynote.tabPanel]
				});
				var oTime;
				window.onresize = function() {    
					if (oTime){   
						 clearTimeout(oTime);   
					}
					oTime = setTimeout(function(){
						// 重新设置tab页尺寸
						Anynote.resizeActiveTab();
						// 设置上传窗口最小化后按钮的位置
						var left = $(window).width() - 150;
						var top = $(window).height() - 60;
						$("#minUploadWinDiv").css("left", left);
						$("#minUploadWinDiv").css("top", top);
					}, 200); //延迟200毫秒执行
				};

				// 初期化上传窗口最小后后的按钮
	    	    Anynote.initMinUploadWinBtn('minUploadWinDiv');
			}
		});
	</script>
</head>
<body>
	<!-- 菜单用Div -->
	<div id="menuDiv" class="x-hide-display">
       <div id="homeAccordionDiv"></div>
       <div id="todoAccordionDiv"></div>
       <div id="noteAccordionDiv"></div>
       <div id="feedAccordionDiv"></div>
       <div id="pictureAccordionDiv"></div>
       <div id="documentAccordionDiv"></div>
       <div id="accountAccordionDiv"></div>
       <div id="systemAccordionDiv"></div>
    </div>
    <!-- 上传按钮最小化用Div -->
    <div id="minUploadWinDiv"></div>
    <!-- 锁定用Div -->
    <div id="lockDiv" class="x-border-layout-ct" style="position:absolute;width:100%;height:100%;z-index:9999;display:none;">
    	<table id="logo-table">
			<tr>
				<td align="center" height="40"><a href="<%=baseUrl %>"><img src="<%=baseUrl %>/websrc/image/Anynote.png"></img></a></td>
			</tr>
		</table>
    	<div id="lockWindowDiv" style="margin-top:65px;"></div>
    </div>
    <!-- 文件下载用Form -->
    <form id="downloadForm" name="downloadForm" action="" method="post" target="_self"></form>
</body>
</html>
